package com.lanhai.javaBean;

import java.awt.geom.GeneralPath;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.lanhai.model.LimitArea;
import com.lanhai.utils.RegionUtil;
import com.lanhai.utils.StringUtil;
import com.mybatis.dao.LimitAreaDao;

public class LimitAreaBean {

	/**
	 * 限行区列表
	 */
	public static List<LimitArea> loadData(SqlSessionFactory sqlSessionFactory){
		List<LimitArea> limitAreaList = new ArrayList<LimitArea>();
		SqlSession sqlSession = sqlSessionFactory.openSession();
		try {
			LimitAreaDao laDao = sqlSession.getMapper(LimitAreaDao.class);
			List<Map<String, Object>> list = laDao.selectAll();
			if(list.size() > 0){
				for(Map<String, Object> m:list){
					LimitArea limitArea = new LimitArea();
					limitArea.setId((Integer)m.get("id"));
					limitArea.setName((String)m.get("name"));//名称
					limitArea.setLimitQty((Integer)m.get("limitQty"));//限行数量
					limitArea.setItem((Integer)m.get("item"));//排序
					limitArea.setStep((Integer)m.get("step"));//所属工序
					String xStr = (String)m.get("mapXArr");
					boolean flag = false;
					if(xStr != null){
						Double[] mapXArr = StringUtil.convertDoubleArray(xStr);
						limitArea.setMapXArr(mapXArr);
						flag = true;
					}
					String yStr = (String)m.get("mapYArr");
					if(yStr != null){
						Double[] mapYArr = StringUtil.convertDoubleArray(yStr);
						limitArea.setMapYArr(mapYArr);
					}
					if(flag){
						GeneralPath shape = RegionUtil.getCtrlShape(limitArea.getMapXArr(), limitArea.getMapYArr());
						limitArea.setShape(shape);
					}
					limitAreaList.add(limitArea);					
				}
			}
	    }catch(Exception e){
	    	e.printStackTrace();
	    }finally{
	    	sqlSession.close();
	    }
        return limitAreaList;
	}
	
}
